package cn.bytecollege.merchant.dao;

import cn.bytecollege.common.dao.BaseDao;
import cn.bytecollege.common.entity.Merchant;

import java.util.List;

public class MerchantDao extends  BaseDao{

        /**
         *根据商家名查询商家信息
         */
        public Merchant findMerchantByMerchantname(String merchantname){
            String sql ="select merchant_name,merchant_particulars,merchant_id,product_id,merchant_password from merchant where merchant_name = ?";
            List<Merchant> list = helper.executeQuery(sql,Merchant.class,merchantname);
            Merchant merchant = null;
            //判断数据库里是否有数据
            if (list.size()>0){
                merchant = list.get(0);
            }
            return merchant;
        }

        /**
         * 注册用户
         */
        public int merchantSave(Merchant merchant){
            String sql = "insert into merchant (merchant_name,merchant_password,merchant_particulars) "+
                    "values(?,?,?)";
            Object[] objects = {merchant.getMerchantName(),merchant.getMerchantPassword(),merchant.getMerchantParticulars()};
            return helper.executeUpdate(sql,objects);
        }
//        public int updatemerchant(Merchant merchant){
//            String sql = "update merchant set merchantname=?,merchant_password=?,merchant_phonenumber=?,merchant_head_protrait=?,merchant_gender=?"
//                    +"where merchant_id=?";
//            Object[] objects ={merchant.getmerchantname(),merchant.getmerchantPassword(),merchant.getmerchantPhonenumber(),merchant.getmerchantHeadPortrait()
//                    ,merchant.getmerchantGender()};
//            return  helper.executeUpdate(sql,merchant);
//        }
//
//        /**
//         * 根据merchantId查询merchant信息
//         * @param merchantId
//         * @return
//         */
//        public Merchant findmerchantBymerchantId(Integer merchantId){
//            String sql ="select merchant_Id,merchantname,merchant_nickname,merchant_phonenumber,merchant_gender,merchant_head_portrait from merchant where merchant_id = ?";
//            List<merchant> list = helper.executeQuery(sql,merchant.class,merchantId);
//            merchant merchant = null;
//            //判断数据库里是否有数据
//            if (list.size()>0){
//                merchant = list.get(0);
//            }
//            return merchant;
//        }
//
//        /**
//         * 根据id修改用户信息
//         * @param merchant
//         * @return
//         */
//        public int merchantUpdateById(Merchant merchant){
//            String sql = "update merchant set merchant_nickname = ? ,merchant_phonenumber= ? ,merchant_gender= ?   where merchant_id = ? ";
//            Object [] objects = {merchant.getmerchantNickname(),merchant.getmerchantPhonenumber(),merchant.getmerchantGender(),merchant.getmerchantId()};
//            return helper.executeUpdate(sql,objects);
//        }
    }


